<?php
/**
 * admin表模型
 * @author hedong <2015-12-07 16:31:45>
 */
namespace Admin\Model;

use Think\Model;

class SellerModel extends Model {

    /**
     * 商家分类转换
     * @param $type
     * @return mixed
     */
    public function typeToStr($type){
        $data = [
            '10' => '衣',
            '20' => '食',
            '30' => '住',
            '40' => '行',
            '50' => '悦',
        ];
        return $data[$type];
    }


    /**
     * 结算
     * @param $id       结算表id
     * @return int      1成功  -1失败   0记录不存在或者已结算
     */
    public function over($id){
        //判断是否未结算
        $data = M('user_cardlog')->where(['id'=>$id, 'is_balance'=>0])->find();
        if($data){
            M()->startTrans();
            //1. 结算操作   （未实现）
            $res1 = true;



            //2. 修改状态
            $info['balancetime'] = time();
            $info['is_balance'] = 1;
            $res2 = M('user_cardlog')->where(['id'=>$id])->save($info);
            if($res1 && $res2){
                M()->commit();
                return 1;
            }else{
                M()->rollback();
                return -1;
            }
        }else{
            return 0;
        }
    }
}
?>